home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
com
/
othernet
/
fidonet
/
btnc200
/
config.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-10
|
7KB
|
304 lines
/*
** Program: BTNC
**
** Module: Configuration parser
*/
#include <portab.h>
#include <stdio.h>
#include <stdlib.h>
#include <ext.h>
#include <string.h>
#include <ctype.h>
#include "general.h"
#include "globals.h"
#include "logfile.h"
/* Modified -------------- */
EXTERN BYTE CopyrightMessage[];
/* ------------------------ */
MLOCAL struct ffblk fileinfo;
VOID ProcessLine(BYTE *line, BYTE *s, BYTE *p1, BYTE *p2, BYTE *p3)
{
BYTE *pos,
*token;
pos = strchr(line, ';');
if (pos) *pos = EOS;
pos = strchr(line, '\n');
if (pos) *pos = EOS;
token = strtok(line, " ");
*s = *p1 = *p2 = *p3 = EOS;
if (token)
{
strcpy(s, token);
strupr(s);
token = strtok(NULL, " ");
if (token)
{
strcpy(p1, token);
token = strtok(NULL, " ");
if (token)
{
strcpy(p2, token);
token = strtok(NULL, " ");
if (token) strcpy(p3, token);
}
}
}
}
WORD SearchValidList(BYTE *basename)
{
BYTE mask[13],
buffer[128];
BYTE *ext;
BOOLEAN found;
strcpy(mask, basename);
strcat(mask, ".???");
found = findfirst(mask, &fileinfo, 0x27);
while (found == SUCCESS)
{
strcpy(buffer, fileinfo.ff_name);
ext = strchr(buffer, '.') + 1L;
if (isdigit(*ext) && isdigit(ext[1]) && isdigit(ext[2]))
{
strcpy(basename, strupr(fileinfo.ff_name));
return(SUCCESS);
}
found = findnext(&fileinfo);
}
return(FAILURE);
}
VOID ParseConfig(WORD argc, BYTE **argv)
{
BYTE filename[128],
line[256],
statement[128],
par1[128], par2[128], par3[128];
FILE *cfgfile;
ADDRESS addr;
DOMAINSPEC *ndomain,
*ldomain = NULL;
ADDLIST *nadd,
*ladd = NULL;
POINTLIST *npl,
*lpl = NULL;
/*
** Check for -c Flag on commandline
*/
if (argc > 1)
{
if (stricmp (argv[1], "-c") == 0)
c_format = TRUE;
else
ERR_printf("\nIllegal flag '%s' on commandline\n", argv[1]);
}
strcpy(filename, "NODELIST.CFG");
cfgfile = fopen(filename, "r");
if (cfgfile == NULL)
ERR_printf("\nCouldn't read configuration file '%s', defaults are used.\n", filename);
else
{
while (fgets(line, 127, cfgfile) != NULL)
{
ProcessLine(line, statement, par1, par2, par3);
/* Modified -------------------------- */
if (strcmp(statement, "LOGFILE") == SUCCESS)
{
if (*par1 == EOS)
{
ERR_puts("\nMissing filename in 'Logfile' statement!\n");
strcpy(logname,"BTNC.LOG");
}
else strcpy(logname,par1);
logfile_open(logname);
LOG_puts(&CopyrightMessage[1]);
#ifdef ALPHA
LOG_puts(AlphaVersion);
#endif
#ifdef BETA
LOG_puts(BetaVersion);
#endif
write_logfile = TRUE;
}
/* ----------------------------------- */
if (strcmp(statement, "MAKEUSERLIST") == SUCCESS)
userlist = TRUE;
if (strcmp(statement, "DISPLAY") == SUCCESS)
display = TRUE;
if (strcmp(statement, "STATISTICS") == SUCCESS)
statistics = TRUE;
if (strcmp(statement, "USERLISTNAME") == SUCCESS)
{
if (*par1 == EOS)
ERR_puts("\nMissing <userlistspec> parameter in 'UserlistName' statement!\n");
else
strcpy(userlist_name, par1);
}
if (strcmp(statement, "POINTLIST") == SUCCESS)
{
if (*par1 == EOS)
{
ERR_puts("\nMissing <file> parameter in 'PointList' statement!\n");
ERR_puts("\nMissing <bossnode> parameter in 'PointList' statement!\n");
}
if (*par1 && *par2 == EOS)
ERR_puts("\nMissing parameter in 'PointList' statement!\n");
if (*par1 != EOS && *par2 != EOS)
{
if (findfirst(par1, &fileinfo, 0x27) == SUCCESS)
{
sscanf(par2, "%u:%u/%u.%u", &(addr.zone),
&(addr.net), &(addr.node), &(addr.point));
if (addr.point)
{
ERR_printf("\nFunny: You want add a pointlist to a point system (.%u)?\n", addr.point);
ERR_puts("\nGood joke ! :-) I'll treat it as if you meant his boss.\n");
addr.point = 0;
}
if (strchr(par2, ':') == NULL || addr.net == 0 ||
addr.zone == 0)
{
if (strchr(par2, ':') == NULL)
ERR_puts("\nInvalid <bossnode> address: zone missing. Pointlist not added.\n");
else
{
if (addr.zone == 0)
ERR_puts("\nInvalid <bossnode> address: zone can't be zero. Pointlist not added.\n");
if (addr.net == 0)
ERR_puts("\nInvalid <bossnode> address: net can't be zero. Pointlist not added.\n");
}
}
else
{
npl = NewAtom(POINTLIST);
npl->boss.zone = addr.zone;
npl->boss.net = addr.net;
npl->boss.node = addr.node;
strcpy(npl->listfile, par1);
if (pointlists == NULL)
pointlists = npl;
if (lpl != NULL)
lpl->next = npl;
lpl = npl;
}
}
else
ERR_printf("\nCouldn't find pointlist '%s'. Not added.\n", par1);
}
}
if (strcmp(statement, "DOMAIN") == SUCCESS)
{
if (*par1 == EOS || *par2 == EOS)
ERR_puts("\nMissing expected parameter(s) in 'Domain' statement!\n");
else
{
strlwr(par1);
ndomain = NewAtom(DOMAINSPEC);
strcpy(ndomain->dat.name, par1);
if (SearchValidList(par2) == SUCCESS)
{
strcpy(ndomain->dat.listfile, par2);
if (*par3 != EOS)
ndomain->dat.zone = atoi(par3);
else
ndomain->dat.zone = MULTIZONE;
}
else
ERR_printf("\nCouldn't find a valid <%s> file! Domain ignored.\n", par2);
if (domains == NULL) domains = ndomain;
if (ldomain != NULL) ldomain->next = ndomain;
ldomain = ndomain;
}
}
if (strcmp(statement, "ADDLIST") == SUCCESS)
{
if (*par1 == EOS || *par2 == EOS)
ERR_puts("\nMissing expected parameter(s) in 'AddList statement!\n");
else
{
nadd = NewAtom(ADDLIST);
strcpy(nadd->listfile, par1);
sscanf(par2, "%u:%u", &nadd->tozone, &nadd->toregion);
if (addlists == NULL) addlists = nadd;
if (ladd != NULL) ladd->next = nadd;
ladd = nadd;
/* Modified ------------------------- */
if (stricmp(par3, "4D") == SUCCESS)
{
nadd->dimension4=TRUE;
}
else if (stricmp(par3, "NF") == SUCCESS)
{
nadd->new_3D_format=TRUE; /* New German Format */
}
/* ---------------------------------- */
}
}
}
fclose(cfgfile);
}
}